from .Hybrid_Sim import HybridSim

# hybrid = HybridSim.get_Final_sim('地球', '天体')

def GetMaxList(keylist, anslist): # 在关键词列表和答案列表中寻找最佳匹配对

	result = []

	for key in keylist: # 在答案中寻找跟每个关键词最接近的词

		if key in anslist: # 如果该词已在答案列表中
			result.append([key, key, 1])
			continue

		if HybridSim.in_vocab(key) == 0: # 如果该词未被收录则跳过
			print(key,'该词未被收录！')
			continue

		maxsim = 0.0	# 记录最高得分
		simans = ''		# 记录答案词

		for ans in anslist:
			sim = HybridSim.get_Final_sim(key, ans)

			if sim > maxsim:
				maxsim = sim
				simans = ans

		# if simans in anslist: # 删除答案中的该词
		# 	anslist.remove(simans)

		if maxsim > 0: # 如果有相似词则返回
			result.append([key,simans,maxsim])
	# print(result)
	return result

def GetStrSim(keylist, anslist):
    res = GetMaxList(keylist, anslist)
    num = len(keylist)
    point = 0
    for each in res:
        point += each[2]
    #     print('得分：',each[2])
    # print('res:',res)
    # print('关键词分词数num:',num)
    # print('总得分point：',point)
    return point/num

if __name__ == '__main__':

	GetMaxList(['今天','晚饭','白天'], ['下雨','夜晚','早餐'])